import request from '@/utils/request'

// 获取角色列表
export function getRoleList() {
  return request({
    url: '/roles?page=1&size=10',
    method: 'get',
  })
}

// 获取角色详情
export function getRoleDetail(roleId) {
  return request({
    url: `/roles/${roleId}`,
    method: 'get'
  })
}

// 新增角色
export function addRole(data) {
  return request({
    url: '/roles',
    method: 'post',
    data
  })
}

// 更新角色
export function updateRole(roleId, data) {
  return request({
    url: `/roles/${roleId}`,
    method: 'put',
    data
  })
}

// 删除角色
export function deleteRole(roleId) {
  return request({
    url: `/roles/${roleId}`,
    method: 'delete'
  })
}

// 启用角色
export function enableRole(roleId) {
  return request({
    url: `/roles/${roleId}/enable`,
    method: 'put'
  })
}

// 禁用角色
export function disableRole(roleId) {
  return request({
    url: `/roles/${roleId}/disable`,
    method: 'put'
  })
}

// 分配权限
export function assignPermissions(roleId, permissionIds) {
  return request({
    url: `/roles/${roleId}/permissions`,
    method: 'post',
    data: { permissionIds }
  })
}
//获取角色分页
export let rolePageSize=(obj)=>{
  const params = new URLSearchParams();
  
  // 基础分页参数
  params.append('page', obj.page || 1);
  params.append('size', obj.size || obj.pageSize || 10);
  
  // 筛选参数
  if (obj.roleName) {
    params.append('roleName', obj.roleName);
  }
  if (obj.status) {
    params.append('status', obj.status);
  }
  
  return request({
    url: `/roles?${params.toString()}`,
    method: 'get'
  })
}
